package com.wo56.pushmsgcenter.common.utils;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

import com.framework.core.util.SysStaticDataUtil;
import com.wo56.pushmsgcenter.common.annotation.CodeTypeConverter;

public class BeanUtils {
	public static void copyProperties(Object dest, Object orig) throws IllegalAccessException, InvocationTargetException{
		com.framework.core.util.BeanUtils.copyProperties(dest, orig);
		Field[] fields = dest.getClass().getDeclaredFields();
		for(Field field:fields){
			CodeTypeConverter con = field.getAnnotation(CodeTypeConverter.class);
			if(con!=null){
				String codeType = con.value();
				field.setAccessible(true);
				if(field.get(dest)!=null){
					String value = String.valueOf(field.get(dest));
					if(value != null&&!"".equals(value)){
						String realValue = SysStaticDataUtil.getSysStaticDataCodeName(codeType, value);
						field.set(dest, realValue);
					}
				}
			}
			
		}
	}
	
	
	public static void main(String[] args) throws IllegalAccessException, InvocationTargetException {
//		ConvertUtils.register(new StringConverter(), String.class);
//		TransportationContract bean = new TransportationContract();
//		bean.setDateSigned(new Date());
//		TransportationContractReq xmlBean = new TransportationContractReq();
//		BeanUtils.copyProperties(xmlBean, bean);
//		System.out.println(xmlBean.getDateSigned());
//		String[] pros= SysContexts.getClassMetadata(CarrierCredit.class).getPropertyNames();
//		boolean[] abilitys= SysContexts.getClassMetadata(CarrierCredit.class).getPropertyNullability();
//		for(int i=0;i<pros.length;i++){
//			System.out.println(pros[i]+"=="+abilitys[i]);
//		}
//		SysContexts.getClassMetadata(Carrier.class).getPropertyNullability();
		
	}
}
